$(function(){
	var userGrid = $("#whStudentGrid");

	//初始化
	userGrid.datagrid({
		url:'relation/list',
		fit:true,
		border:false,//是否有边框线
		fitColumns:true,//是否布满整个屏幕
		singleSelect:true,
		rownumbers:true,//显示行数
		emptyMsg:"<img src='public/images/noGDXX.png'>",
		pagination : true,// 是否显示分页栏
		columns : [ [ {
			field : 'student.name',
			title : '姓名',
			align : 'center',
			width : 100,
			formatter : function(value, rec) {
				return rec.student['name'];
			}
		},
		{
			field : 'student.gender',
			title : '性别',
			align : 'center',
			width : 80,
			formatter : function(value, rec) {
				if(rec.student.gender =='女'){
					 return '<img src="public/images/female.png" title="我是妹子">';
				}else if(rec.student.gender =='男'){
					 return '<img src="public/images/male.png" title="我是帅锅">';
				}
			}
		},
		{
			field : 'company',
			title : '公司名称',
			align : 'center',
			
			width : 150
		},
		{
			field : 'offer.path',
			title : 'offer',
			align : 'center',
			hidden : 'true',
			width : 80,
			formatter : function imgFormatter(value, rec) {
				if(rec.offer == null){
					return '';
				}
				return rec.offer['path'];
			}
		},{
			field : 'address',
			title : '公司地址',
			align : 'center',
			width : 150
		},
		{
			field : 'trialSalary',
			title : '试用薪水',
			align : 'center',
			width : 80
		},
		{
			field : 'salary',
			title : '薪水',
			align : 'center',
			width : 80
		},
		{
			field : 'gdtime',
			title : '毕业时间',
			align : 'center',
			width : 100
		},
		{
			field : 'getjobtime',
			title : '入职时间',
			align : 'center',
			width : 100
		},{
			field : 'ac',
			title : '操作',
			width : 150,
			align : 'center',
			formatter:function(value,row,index){
				var bts = [];
				if(userGrid.datagrid('getData').rows[index].offer != null){
					bts.push('<a id="' + row.id + '" data-id="' + row.id
							+ '" data-index="' + index
							+ '" class="ctr" target="_Blank" href="teaemploy/saveGraduation/'+userGrid.datagrid('getData').rows[index].offer.path+'">offer预览</a>');
				}
				bts.push('<a data-id="'+row.id+'" data-index="'+index+'" class="ctr delete">删除</a>');
				
				return bts.join('');
			}
		} ] ]
	});

	var student = $("#student");
	//检索按钮
	$("#studentSearch").on("click",function(){
		userGrid.datagrid("load",{
			student :  student.val() 
		});
	});
	var form = $("#studentSearchForm");
	$("#studentReset").on('click', function() {
		form.form('clear');
		// 清除查询参数
		userGrid.datagrid("load", {});
	});
	
	
	var studialog;


	var gridPanel = userGrid.datagrid("getPanel");
	gridPanel.on("click","a.delete",function(){
		var index = this.dataset.index;
		var id = this.dataset.id;
		$.messager.confirm("提示","您确定要删除此数据吗？",function(r){
			if(r){
				$.get("relation/delete/"+id,function(rs){
					if(rs.success){
						$.messager.alert("提示","操作成功！该数据已被彻底删除");
						userGrid.datagrid("reload");
					}else{
						$.messager.alert("提示", obj.message);
					}
				});
			}
		});
	});
	



});